package com.forfunnet.minjian.message.response;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * Created by RexQian on 2014/12/9.
 */

@JsonIgnoreProperties(ignoreUnknown = true)
public class BaseResponse {
    public ResponseStatus ResponseStatus;

    public static String getErrorMessage(BaseResponse resp)
    {
        if (resp == null)
        {
            return "网络不给力，请稍候再试";
        }
        else if (resp.ResponseStatus != null && resp.ResponseStatus.Message != null)
        {
            String errMsg = "";
            if (resp.ResponseStatus.Errors != null && resp.ResponseStatus.Errors.size() > 0)
            {
                errMsg = resp.ResponseStatus.Errors.get(0).Message;
            }
            else
            {
                errMsg = resp.ResponseStatus.Message;
            }
            return errMsg;
        }

        return null;
    }

    public static boolean hasError(BaseResponse resp)
    {
        return resp == null
                || (resp.ResponseStatus != null && resp.ResponseStatus.Message != null);
    }
}
